<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑业主</title>
  </head>
  <body>
    <script type="text/javascript">
      Ext.onReady(function(){
        var houseSubType = new Ext.form.Hidden({
          name: 'house_sub_type'
        });
        var buildingUnitTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item">', '<div style="float:left; width:90px">{number}</div><div>{name}</div>', '</div></tpl>');
        var buildingUnitStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/building/getAllBuildingUnits"
          }),
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'name'
            }, {
              name: 'number'
            }, {
              name: 'sub_type'
            }])
        });
        //建筑单元
        var buildingUnit = new Ext.form.ComboBox({
          width:350,
          store: buildingUnitStore,
          fieldLabel: '楼座单元',
          allowBlank: false,
          blankText: "楼座单元必须选择",
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'building_id',//如果不想提交displayField，则在这儿指定要提交的Key，value就是valueField．
          emptyText: '请选择楼座单元...',
          //typeAhead: false,
          loadingText: '搜索中...',
          anchor: '90%',
          //pageSize: 10,
          //hideTrigger: false,
          //readOnly:true,
          tpl: buildingUnitTemplate,
          minChars: 3,
          editable: true,
          mode: 'remote',
          triggerAction: 'all',
          editable:false,
          itemSelector: 'div.search-item',
          selectOnFocus:true
        });

        buildingUnit.on('select', function(combo, record, index) {
          var subType = record.get('sub_type');
            //判断值多层还是高层，以设置水表数allowbank
            if (subType == "多层"){
              waterMeter.allowBlank =  true;
              liftPayYear.setDisabled(true);
              liftPayMonth.setDisabled(true);
              waterPayYear.setDisabled(true);
              waterPayMonth.setDisabled(true);
            }else{
              waterMeter.allowBlank =  false;
              liftPayYear.setDisabled(false);
              liftPayMonth.setDisabled(false);
              waterPayYear.setDisabled(false);
              waterPayMonth.setDisabled(false);
            }
            if (this.isExpanded()) {
              this.collapse();
            }
        });

        
        var doorPlate = new Ext.form.TextField({
          fieldLabel: '门牌号',
          allowBlank: false,
          name: 'doorplate',
          anchor: '90%'
        });

        var houseId = new Ext.form.Hidden({
          name: 'id'
        });
        
        var owner = new Ext.form.TextField({
          fieldLabel: '业主姓名',
          allowBlank: false,
          name: 'owner',
          anchor: '90%'
        });

        var phone = new Ext.form.TextField({
          fieldLabel: '业主电话',
          allowBlank: false,
          name: 'phone',
          anchor: '90%'
        });

        var area =  new Ext.form.NumberField({
          fieldLabel: '面积',
          allowBlank: false,
          name: 'area',
          allowDecimals: true,
          allowNegative: false,
          anchor: '90%'
        });

        var waterMeter =  new Ext.form.NumberField({
          fieldLabel: '水表数',
          allowBlank: false,
          name: 'water_last_meter',
          allowDecimals: true,
          allowNegative: false,
          anchor: '90%'
        });

        var balance =  new Ext.form.NumberField({
          fieldLabel: '余额',
          name: 'balance',
          allowDecimals: true,
          allowNegative: false,
          anchor: '90%'
        });
        
        var moveIn =  new Ext.form.DateField({
          fieldLabel: '入住日期',
          name: 'move_in',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: true,
          emptyText: '请选择日期...',
          anchor: '90%'
        });

        //-----------------------物业费----------------------------
        var propertyPayYear = new Ext.form.ComboBox({ //combobox
          name: 'property_pay_year',
          fieldLabel: '物业费-年',
          width: '90',
          resiable: true,
          typeAhead: true,
          allowBlank: false,
          handleHeight: 100, //
          displayField: 'key',
          valueField: 'value',
          selectOnFocus: true,
          mode: 'local',
          triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
          emptyText: '选择年...',
          store: new Ext.data.Store({
            data: [ ['2004', '2004'], ['2005', '2005'], ['2006', '2006'], ['2007', '2007'],['2004', '2004'],['2005', '2005'],['2006', '2006'],['2007', '2007'],['2008', '2008'], ['2009', '2009'], ['2010', '2010'], ['2011', '2011'], ['2012', '2012']],
            reader: new Ext.data.ArrayReader({
              id: 0
            }, [{
                name: 'value'
              }, {
                name: 'key'
              }])
          }), //数据储存到这个comboBox
          anchor: '90%'
        });
        propertyPayYear.setValue(new Date().clearTime(true).getFullYear());
        var propertyPayMonth = new Ext.form.ComboBox({ //combobox
          name: 'property_pay_month',
          fieldLabel: '月',
          width: '90',
          resiable: true,
          typeAhead: true,
          allowBlank: false,
          handleHeight: 100, //
          displayField: 'key',
          valueField: 'value',
          selectOnFocus: true,
          mode: 'local',
          triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
          emptyText: '选择月...',
          store: new Ext.data.Store({
            data: [['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'],['7', '7'], ['8', '8'], ['9', '9'], ['10', '10'], ['11', '11'], ['12', '12']],
            reader: new Ext.data.ArrayReader({
              id: 0
            }, [{
                name: 'value'
              }, {
                name: 'key'
              }])
          }), //数据储存到这个comboBox
          anchor: '90%'
        });
        //----------------------------电梯费------------------------------------
        var liftPayYear = new Ext.form.ComboBox({ //combobox
          name: 'lift_pay_year',
          fieldLabel: '电梯费-年',
          width: '90',
          resiable: true,
          typeAhead: true,
          allowBlank: false,
          handleHeight: 100, //
          displayField: 'key',
          valueField: 'value',
          selectOnFocus: true,
          mode: 'local',
          triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
          emptyText: '选择年...',
          store: new Ext.data.Store({
            data: [['2004', '2004'],['2005', '2005'],['2006', '2006'],['2007', '2007'],['2008', '2008'], ['2009', '2009'], ['2010', '2010'], ['2011', '2011'], ['2012', '2012']],
            reader: new Ext.data.ArrayReader({
              id: 0
            }, [{
                name: 'value'
              }, {
                name: 'key'
              }])
          }), //数据储存到这个comboBox
          anchor: '90%'
        });
        liftPayYear.setValue(new Date().clearTime(true).getFullYear());
        var liftPayMonth = new Ext.form.ComboBox({ //combobox
          name: 'lift_pay_month',
          fieldLabel: '月',
          width: '90',
          resiable: true,
          typeAhead: true,
          allowBlank: false,
          handleHeight: 100, //
          displayField: 'key',
          valueField: 'value',
          selectOnFocus: true,
          mode: 'local',
          triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
          emptyText: '选择月...',
          store: new Ext.data.Store({
            data: [['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'],['7', '7'], ['8', '8'], ['9', '9'], ['10', '10'], ['11', '11'], ['12', '12']],
            reader: new Ext.data.ArrayReader({
              id: 0
            }, [{
                name: 'value'
              }, {
                name: 'key'
              }])
          }), //数据储存到这个comboBox
          anchor: '90%'
        });
        //------------------------------水费------------------------------------
        var waterPayYear = new Ext.form.ComboBox({ //combobox
          name: 'water_pay_year',
          fieldLabel: '水费-年',
          width: '90',
          resiable: true,
          typeAhead: true,
          allowBlank: false,
          handleHeight: 100, //
          displayField: 'key',
          valueField: 'value',
          selectOnFocus: true,
          mode: 'local',
          triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
          emptyText: '选择年...',
          store: new Ext.data.Store({
            data: [['2004', '2004'],['2005', '2005'],['2006', '2006'],['2007', '2007'],['2008', '2008'], ['2009', '2009'], ['2010', '2010'], ['2011', '2011'], ['2012', '2012']],
            reader: new Ext.data.ArrayReader({
              id: 0
            }, [{
                name: 'value'
              }, {
                name: 'key'
              }])
          }), //数据储存到这个comboBox
          anchor: '90%'
        });
        waterPayYear.setValue(new Date().clearTime(true).getFullYear());
        var waterPayMonth = new Ext.form.ComboBox({ //combobox
          name: 'water_pay_month',
          fieldLabel: '月',
          width: '90',
          resiable: true,
          typeAhead: true,
          allowBlank: false,
          handleHeight: 100, //
          displayField: 'key',
          valueField: 'value',
          selectOnFocus: true,
          mode: 'local',
          triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
          emptyText: '选择月...',
          store: new Ext.data.Store({
            data: [['2', '2'], ['4', '4'], ['6', '6'], ['8', '8'], ['10', '10'], ['12', '12']],
            reader: new Ext.data.ArrayReader({
              id: 0
            }, [{
                name: 'value'
              }, {
                name: 'key'
              }])
          }), //数据储存到这个comboBox
          anchor: '90%'
        });
        
        //提交按钮
        var editHouseButton = new Ext.Button({
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            editHouseButton.setDisabled(true);
            if (editHouseFormPanel.form.isValid()) {
              editHouseFormPanel.form.submit({
                success: function(result, resp){
                  if (resp.result.info.indexOf("成功") >= 0) {
                    editHouseWin.destroy();
                  } else {
                    Ext.MessageBox.alert('消息', resp.result.info);
                    editHouseButton.enable();
                  }
                },
                failure: function(result, request){
                  editHouseButton.enable();
                  Ext.MessageBox.alert('消息', '服务器的通信失败!');
                }
              });
            }
            else {
              editHouseButton.enable();
              //Ext.MessageBox.alert('输入验证有错', '请输入必输选项');
            }
          }
        })
        
        var editHouseFormPanel = new Ext.form.FormPanel({
          labelWidth: 65,
          width: '470',
          labelAlign: 'right',
          frame : true,
          url: '/house/updateHouse',
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'owner'
            }, {
              name: 'doorplate'
            }, {
              name: 'phone'
            }, {
              name: 'area'
            }, {
              name: 'balance'
            }, {
              name: 'move_in',
              type: 'date',
              dateFormat: 'Y/m/d'
            }, {
              name: 'building_id',
              mapping: 'building.number'
            }, {
              name: 'house_sub_type',
              mapping: 'building.sub_type'
            }, {
              name: 'property_pay_year'
            }, {
              name: 'property_pay_month'
            }, {
              name: 'lift_pay_year'
            }, {
              name: 'lift_pay_month'
            }, {
              name: 'water_pay_year'
            }, {
              name: 'water_pay_month'
            }]),
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .68,
                  layout: 'form',
                  border: false,
                  items: [buildingUnit]
                },{
                  columnWidth: .3,
                  layout: 'form',
                  border: false,
                  items: [doorPlate]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [owner]
                },{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [phone]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [area]
                }, {
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [balance]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [moveIn]
                }, {
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [waterMeter]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [propertyPayYear]
                }, {
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [propertyPayMonth]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [liftPayYear]
                }, {
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [liftPayMonth]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [waterPayYear]
                }, {
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [waterPayMonth]
                }]
            },houseId,houseSubType],
          buttons: [editHouseButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                editHouseWin.destroy();
              }
            }]
        });
        
        editHouseFormPanel.render('edit_house_form');
        editHouseFormPanel.form.load({
          url: '/house/getHouseById?house_id=<%=@houseId%>',
          waitMsg: '正在载入数据...',
          success: function(form, action){
            //根据业主类型是多层或高层，处理电梯和水电的输入问题。
            if (houseSubType.getValue() == "多层"){
              waterMeter.allowBlank =  true;
              liftPayYear.setDisabled(true);
              liftPayMonth.setDisabled(true);
              waterPayYear.setDisabled(true);
              waterPayMonth.setDisabled(true);
            }else{
              waterMeter.allowBlank =  false;
              liftPayYear.setDisabled(false);
              liftPayMonth.setDisabled(false);
              waterPayYear.setDisabled(false);
              waterPayMonth.setDisabled(false);
            }
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
      })
    </script>
    <div id="edit_house_form"></div>
  </body>
</html>
